package com.xigua._链表;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/3/1919:05
 */
public class _剑指Offer52_两个链表的第一个公共节点 {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) return null;
        ListNode A = headA;
        ListNode B = headB;
        while (A !=null || B != null){
            if (A == null){
                A = headB;
            }else if (B == null){
                B = headA;
            }else {
                if (A == B) return A;
                A = A.next;
                B = B.next;
            }

        }
        return null;

    }
}
